package test2.greedy;

import java.util.Stack;

public class Solution {

    public String strWithout3a3b(int A, int B) {
        // 在此处写入代码
        Stack<Character> stack = new Stack<>();
        int count = 0;
        char c = 'a';
        while (A> 0 || B > 0) {
            if (!stack.isEmpty()) {
                c = stack.peek();
            }

            if ((A>0 && A >= B && count < 2) || (count == 2 && c == 'b') ) {
                stack.push('a');
                if (c == 'a') {
                    count ++;
                } else {
                    count = 1;
                }
                A--;
            } else {
                stack.push('b');
                if (c == 'b') {
                    count ++;
                } else {
                    count = 1;
                }
                B--;
            }

        }
        String s = "";
        while (!stack.isEmpty()) {
            s = stack.pop() + s;
        }
        return s;

    }
}
